<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>舱内患者操作-frame</title>
    <link rel="stylesheet" type="text/css" href="../css/api.css" />
    <link rel="stylesheet" type="text/css" href="../css/style.css" />
    <link rel="stylesheet" type="text/css" href="../css/aui.2.0.css" />
    <style>
        .container {
            display: -webkit-flex;
            display: flex;
            justify-content: flex-start;
            align-items: center;
            width: 100%;
            padding-top: 20px;
        }

        .container>div {
            width: 50% !important;
            flex-wrap: wrap;
            height: 30px;
            line-height: 30px;
        }

        .container>div>p {
            display: inline-block;
            float: left;
            color: #000;
            font-size: 18px;
        }

        .container>div>p:nth-child(1) {
            width: 40%;
            margin: 0;
            padding: 0;
            text-align: left;
            padding-left: 30px;
            box-sizing: border-box;
        }

        .container>div>p:nth-child(2) {
            width: 40%;
            margin: 0;
            padding: 0;
            text-align: left;
            padding-left: 5px;
        }

        .container:nth-child(3)>div:nth-child(1)>p:nth-child(2) {
            border: 1px solid #ccc;
        }

        .container:nth-child(3)>div:nth-child(2)>p:nth-child(2) {
            border: 1px solid #ccc;
        }
        /* 列表 */

        .hospital>div {
            width: 100%;
            height: 40px;
            margin-top: 5px;
        }

        .hospital>div:nth-of-type(odd) {
            background-color: #ddd;
        }

        .hospital>div:nth-of-type(even) {
            background-color: #8bcdfb;
        }

        .hospital>div>span {
            padding-left: 5px;
            display: inline-block;
            height: 40px;
            line-height: 40px;
        }

        .aui-list-item-inner>div {
            display: -webkit-flex;
            display: flex;
            justify-content: space-around;
            align-items: center;
            width: 100%;
        }

        .aui-list-item-inner>div>span:nth-child(1) {
            padding-left: 10px;
            -webkit-box-sizing: border-box;
            -moz-box-sizing: border-box;
            -ms-box-sizing: border-box;
            -o-box-sizing: border-box;
            box-sizing: border-box;
        }

        .aui-list-item-inner>div>span {
            width: 20%;
            text-align: center;
            font-size: 14px;
        }

        .aui-list-item-inner-wrapper>div>span:nth-child(4) {
            display: inline-block;
            background-image: url('../image/nickname.png');
            width: 100px;
            height: 40px;
            background-repeat: no-repeat;
            background-position: 10px 5px;
            background-size: 20px 20px;
            line-height: 40px;
            text-align: left;
            padding-left: 35px;
        }

        .aui-btn-danger {
            background-color: #d4237a !important;
        }

        .aui-btn-info,
        .aui-btn-danger {
            width: 130px !important;
            height: 40px !important;
            line-height: 27px !important;
        }

        .aui-content-odd>ul>li:nth-of-type(odd) {
            background: #f0f0f0;
        }

        .aui-checkbox,
        .aui-list-item-input {
            margin-left: 10px !important;
        }

        .aui-list .aui-list-item-label,
        .aui-list .aui-list-item-label-icon {
            width: 45% !important;
        }

        .container {
            background-color: #fff;
        }
    </style>
</head>

<body>
    <main id="app">
        <div class="aui-content aui-margin-b-15">
            <div style="text-align: center; padding-top: 20px;background-color: #fff;padding-bottom: 20px;">
                <div class="aui-btn aui-btn-info">
                    <span class="aui-iconfont aui-icon-trash" onclick="DeleteTreatment()">移除患者</span>
                </div>
            </div>
            <ul class="aui-list aui-form-list">
                <li class="aui-list-item">
                    <div class="aui-list-item-inner inner-checkbox">
                        <label>暂停治疗<input style="margin-left: 10px;" id="Suspend" type="checkbox" values="暂停治疗" class="aui-switch" v-model="checkedPause"></label>
                    </div>
                    <div class="aui-list-item-inner inner-checkbox">
                        <label>结束治疗<input style="margin-left: 10px;" id="End" type="checkbox" values="结束治疗" class="aui-switch" v-model="finishStatus"></label>
                    </div>
                </li>
                <li class="aui-list-item" v-if="checkedPause || finishStatus">
                    <div class="aui-list-item-inner">
                        <div class="aui-list-item-input">
                            <textarea :placeholder="textareaPlaceholder" id="Reason"></textarea>
                        </div>
                    </div>
                </li>
            </ul>
            <div style="text-align: center; padding-top: 20px;background-color: #fff;padding-bottom: 20px;">
                <div class="aui-btn aui-btn-info">
                    <span class="aui-iconfont aui-icon-paper" onclick="PatientOperation()">提交</span>
                </div>
            </div>
        </div>
        <!-- <div class="container container-options">
            <div>
                <p>姓名：</p>
                <p id="F_paientname"></p>
            </div>
            <div>
                <p>住院号：</p>
                <p id="F_zhuyuannumber"></p>
            </div>
        </div>
        <div class="container container-options">
            <div>
                <p>缴费次数：</p>
                <p contenteditable="true" id="F_reservenumber"></p>
            </div>
            <div>
                <p>金额：</p>
                <p contenteditable="true" id="F_charge"></p>
            </div>
        </div>
        <div style="text-align: center; padding-top: 20px;background-color: #fff;padding-bottom: 20px;">
            <div class="aui-btn aui-btn-info">
                <span class="aui-iconfont aui-icon-paper" onclick="NewRenewals()">新增续费</span>
            </div>
        </div>
        <div class="aui-content aui-content-odd aui-margin-b-15" style="padding-top: 20px;">
            <ul class="aui-list aui-list-in" id="Payment">
                <li class="aui-list-item">
                    <div class="aui-list-item-inner">
                        <div>
                            <span>序号</span>
                            <span>缴费次数</span>
                            <span>收费</span>
                            <span>记录人员</span>
                            <span>登记时间日期</span>
                        </div>
                    </div>
                </li>
            </ul>
        </div> -->
    </main>
</body>

</html>

<script src="../script/api.js" charset="utf-8"></script>
<script src="../script/vue.js" charset="utf-8"></script>
<script src="../js/ToConfigure.js" charset="utf-8"></script>
<script src="../script/aui-toast.js" charset="utf-8"></script>
<script src="../script/aui-dialog.js" charset="utf-8"></script>
<script type="text/javascript">
    apiready = function() {
        var vm = new Vue({
            el: '#app',
            data: {
                finishStatus: false,
                checkedPause: false,
                textareaPlaceholder: '',
                Url_IP: ''
            },
            created() {
                //获取所属医院IP地址
                this.Url_IP = ToConfigure_IP("Gorgeous");

                Query_Pay();
                //*****************************************患者操作***********************************//
                var Query_JsParms = new Object();
                //获取患者ID
                Query_JsParms.F_Id = api.pageParam.F_reserveid;
                if (Query_JsParms.F_Id === '' || Query_JsParms.F_Id === undefined) {
                    return "";
                }
                // //转换为json数据
                // var JsonStr = JSON.stringify(Query_JsParms);
                // api.ajax({
                //     url: this.Url_IP + 'AppointmentRegistration/Query_AppointmentRegistration',
                //     method: 'post',
                //     data: {
                //         values: {
                //             parms: JsonStr
                //         }
                //     }
                // }, function(ret, err) {
                //     if (ret) {
                //         //赋值页面
                //         if (ret !== null && ret !== '') {
                //             document.getElementById('F_paientname').innerHTML = ret[0]['F_paientname'];
                //             document.getElementById('F_zhuyuannumber').innerHTML = ret[0]['F_zhuyuannumber'];
                //         }
                //     } else {
                //         alert(JSON.stringify(err));
                //     }
                // });

            },
            watch: {
                finishStatus: function(data) {
                    if (data) {
                        vm.checkedPause = false;
                        vm.textareaPlaceholder = '结束治疗原因：';
                    } else if (!data && !vm.checkedPause) {
                        vm.cleanStatus();
                    }
                },
                checkedPause: function(data) {
                    if (data) {
                        vm.finishStatus = false;
                        vm.textareaPlaceholder = '暂停治疗原因：';
                    } else if (!data && !vm.finishStatus) {
                        vm.cleanStatus();
                    }
                }
            },
            methods: {
                cleanStatus: function() {
                    vm.textareaPlaceholder = '';
                    vm.finishStatus = false;
                    vm.checkedPause = false;
                }
            }
        })
    }


    //移除患者
    function DeleteTreatment() {
        //获取所属医院IP地址
        var Url_IP = ToConfigure_IP("Gorgeous");

        //预约登记ID
        var F_ID = api.pageParam.F_reserveid;
        //位置ID
        var CCWZID = api.pageParam.CCWZID;
        //舱次ID
        var F_HatchID = api.pageParam.F_HatchID;
        api.ajax({
            url: Url_IP + 'HyperbaricOxygen/CabinTreatment/DeleteTreatment',
            method: 'post',
            dataType: 'String',
            data: {
                values: {
                    F_ID: F_ID,
                    CCWZID: CCWZID
                }
            }
        }, function(ret, err) {
            if (ret == "True") {
                JumpPage();
            } else {
                toast.fail({
                    title: "提交失败",
                    duration: 2000
                });
            }
        });
    }




    //患者操作   暂停治疗  结束治疗
    function PatientOperation() {
        //获取所属医院IP地址
        var Url_IP = ToConfigure_IP("Gorgeous");


        //预约登记ID
        var F_ID = api.pageParam.F_reserveid;
        //位置ID
        var CCWZID = api.pageParam.CCWZID;
        //舱次ID
        var F_HatchID = api.pageParam.F_HatchID;
        var toast = new auiToast();
        var Suspend = $api.val($api.dom("input[id='Suspend']:checked"));
        var End = $api.val($api.dom("input[id='End']:checked"));
        //暂停治疗
        if (Suspend == "on") {
            //暂停原因
            var F_stopbeizhu = document.getElementById("Reason").value;
            if (F_ID != undefined && F_ID != 0 && CCWZID != undefined && CCWZID != 0 && F_HatchID != undefined && F_HatchID != 0) {
                api.ajax({
                    url: Url_IP + 'HyperbaricOxygen/CabinTreatment/StopTreatment',
                    method: 'post',
                    dataType: 'String',
                    data: {
                        values: {
                            F_ID: F_ID,
                            CCWZID: CCWZID,
                            F_HatchID: F_HatchID,
                            F_stopbeizhu: F_stopbeizhu
                        }
                    }
                }, function(ret, err) {
                    if (ret == "True") {
                        JumpPage();
                    } else {
                        toast.fail({
                            title: "提交失败",
                            duration: 2000
                        });
                    }
                });
            } else {
                toast.fail({
                    title: "提交失败,请稍后尝试",
                    duration: 2000
                });
            }
            //结束治疗
        } else if (End == "on") {
            var JsParms = new Object();
            //预约登记ID
            JsParms.F_ID = api.pageParam.F_reserveid;
            //位置ID
            JsParms.CCWZID = api.pageParam.CCWZID;
            //舱次ID
            JsParms.F_HatchID = api.pageParam.F_HatchID;
            //结束原因
            JsParms.F_miaoshu = document.getElementById("Reason").value;
            var JsonStr = JSON.stringify(JsParms);
            if (JsParms.F_ID != undefined && JsParms.F_ID != 0 && JsParms.CCWZID != undefined && JsParms.CCWZID != 0 && JsParms.F_HatchID != undefined && JsParms.F_HatchID != 0) {
                api.ajax({
                    url: Url_IP + 'HyperbaricOxygen/CabinTreatment/StopYuanYin',
                    method: 'post',
                    dataType: 'String',
                    data: {
                        values: {
                            parms: JsonStr,
                            CCWZID: CCWZID
                        }
                    }
                }, function(ret, err) {
                    if (ret == "True") {
                        JumpPage();
                    } else {
                        toast.fail({
                            title: "提交失败",
                            duration: 2000
                        });
                    }
                });
            } else {
                toast.fail({
                    title: "提交失败,请稍后尝试",
                    duration: 2000
                });
            }

        } else {
            toast.fail({
                title: "提交失败,请稍后尝试",
                duration: 2000
            });
        }
    }

    //跳转页面 并且进行刷新
    function comeBack() {
        api.historyBack({  }, function(ret, err) {     
            if (!ret.status) {       
                api.closeWin();
            }  
        });
        api.sendEvent({
            name: 'myEvent',
            extra: {
                state: 'no'
            }
        });
    }

    //跳转页面
    function JumpPage() {
        var dialog = new auiDialog();
        dialog.alert({
            title: "提示",
            msg: '操作成功，是否跳转舱次信息',
            buttons: ['取消', '确定']
        }, function(ret) {
            if (ret.buttonIndex === 1) {

            } else if (ret.buttonIndex === 2) {
                //window.location.href="/patient.html?F_id="+api.pageParam.F_HatchID;
                // var Method = "Query_HO_HatchLocation()";
                // api.execScript({
                //     name: 'patientFrame',
                //     script: Method
                // });


                //跳转舱次详情信息
                // api.openWin({
                //     name: 'patients',
                //     url: './patient.html',
                //     pageParam: {
                //         F_id: api.pageParam.F_HatchID
                //     },
                //     reload: true
                // });
                comeBack();
            }
        })
    }

    //查询患者缴费信息
    function Query_Pay() {
        //获取所属医院IP地址
        var Url_IP = ToConfigure_IP("Gorgeous");

        //查询的条件组合
        var JsParms = new Object();
        //获取预约ID
        JsParms.F_reserveid = api.pageParam.F_reserveid;
        if (JsParms.F_reserveid === '' || JsParms.F_reserveid === undefined) {
            return null;
        }
        JsParms.PageSize = 1000;

        //转成json
        var JsonStr = JSON.stringify(JsParms);
        api.ajax({
            url: Url_IP + 'AppointmentRegistration/Query_Pay',
            method: 'post',
            data: {
                values: {
                    parms: JsonStr
                }
            }
        }, function(ret, err) {
            var Content = '';
            if (ret !== '' && ret !== null) {
                Content += '<li class="aui-list-item">';
                Content += '<div class="aui-list-item-inner aui-list-item-inner-wrapper">';
                Content += '<div>';
                Content += '<span>序号</span>';
                Content += '<span>缴费次数</span>';
                Content += '<span>收费</span>';
                Content += '<span>记录人员</span>';
                Content += '<span>登记时间日期</span>';
                Content += '</div>';
                Content += '</div>';
                Content += '</li>';
                //循环object
                for (var o in ret) {
                    Content += '<li class="aui-list-item">';
                    Content += '<div class="aui-list-item-inner aui-list-item-inner-wrapper">';
                    Content += '<div>';
                    Content += '<span>' + (o - 1 + 2) + '</span>';
                    Content += '<span>' + ret[o]['F_reservenumber'] + '</span>';
                    Content += '<span>' + ret[o]['F_charge'] + '</span>';
                    Content += '<span>' + ret[o]['F_noter'] + '</span>';
                    Content += '<span>' + ret[o]['F_CreatorTime'] + '</span>';
                    Content += '</div>';
                    Content += '</div>';
                    Content += '</li>';
                }
                document.getElementById('Payment').innerHTML = Content;
            }
        });
    }

    //新增患者续费
    function NewRenewals() {
        //获取所属医院IP地址
        var Url_IP = ToConfigure_IP("Gorgeous");

        var JsonStr = GetParameters();
        console.log(JsonStr);
        api.ajax({
            url: Url_IP + 'AppointmentRegistration/Add_Pay',
            method: 'post',
            dataType: 'String',
            data: {
                values: {
                    parms: JsonStr
                }
            }
        }, function(ret, err) {
            var toast = new auiToast();
            if (ret == "True") {
                Query_Pay();
                toast.success({
                    title: "提交成功",
                    duration: 2000
                });
            } else {
                toast.fail({
                    title: "提交失败",
                    duration: 2000
                });
            }
        });
    }

    //获取缴费信息
    function GetParameters() {
        var JsParms = new Object();
        //预约人员F_reserveid
        JsParms.F_reserveid = api.pageParam.F_reserveid;
        if (JsParms.F_reserveid === "" && JsParms.F_reserveid === undefined) {
            return "";
        }
        //缴费次数
        JsParms.F_reservenumber = document.getElementById("F_reservenumber").innerText;
        if (JsParms.F_reservenumber === "" && JsParms.F_reservenumber === undefined) {
            return "";
        }
        //收费金额
        JsParms.F_charge = document.getElementById("F_charge").innerText;
        if (JsParms.F_charge === "" && JsParms.F_charge === undefined) {
            return "";
        }
        return JSON.stringify(JsParms);
    }
</script>
